export default {
	get(url, params) {
		return new Promise((resolve, reject) => {
			// console.log(url)
			uni.request({
				url: url,
				data: params,
				method: 'get',
				header: {
					'X-Requested-With': 'XMLHttpRequest',
					"Accept": "application/json",
					"Content-Type": "application/json; charset=UTF-8",
					"Authorization": "bearer" + uni.getStorageSync('access_token')
				},
				dataType: 'json',
				success: (res) => {
					// debugger
					if (res.statusCode == '200') {
						resolve(res)
					} else {
						// debugger
						uni.showToast({
							title: res.data.error_description,
							icon: 'none',
							duration: 2000
						});
						reject(res)
					}

				},
				fail: (res) => {
					uni.showToast({
						title: res.errMsg,
						icon: 'none',
						duration: 2000
					});
					reject(response)
				}

			})

		});
	},
	post(url, params) {
		return new Promise((resolve, reject) => {

			uni.request({
				method: 'post',
				url: url,
				data: params,
				// 后台配置的header协议
				header: {
					'Content-Type': 'application/x-www-form-urlencoded',
					"Authorization": "bearer" + uni.getStorageSync('access_token')
				},
				success: (res) => {
					// debugger
					if (res.statusCode == '200') {
						resolve(res)
					} else {
						// debugger
						uni.showToast({
							title: res.data.error_description,
							icon: 'none',
							duration: 2000
						});
						reject(res)
					}

				},
				fail: (res) => {
					uni.showToast({
						title: res.errMsg,
						icon: 'none',
						duration: 2000
					});
					reject(response)
				}
			})
		})
	},
	postJson(url, params) {
		return new Promise((resolve, reject) => {
			uni.request({
				method: 'post',
				url: url,
				data: params,
				// 后台配置的header协议
				header: {
					'Content-Type': 'application/json',
					"Authorization": "bearer" + uni.getStorageSync('access_token')
				},
				success: (res) => {
					if (res.statusCode == '200') {
						resolve(res)
					} else {
						// debugger
						uni.showToast({
							title: res.data.error_description,
							icon: 'none',
							duration: 2000
						});
						reject(res)
					}

				},
				fail: (res) => {
					uni.showToast({
						title: res.errMsg,
						icon: 'none',
						duration: 2000
					});
					reject(res)
				}
			})
		})
	},
	putJson(url, params) {
		return new Promise((resolve, reject) => {

			uni.request({
				method: 'put',
				url: url,
				data: params,
				// 后台配置的header协议
				header: {
					'Content-Type': 'application/json',
					"Authorization": "bearer" + uni.getStorageSync('access_token')
				},
				success: (res) => {
					// debugger
					if (res.statusCode == '200') {
						resolve(res)
					} else {
						// debugger
						uni.showToast({
							title: res.data.error_description,
							icon: 'none',
							duration: 2000
						});
						reject(res)
					}

				},
				fail: (res) => {
					uni.showToast({
						title: res.errMsg,
						icon: 'none',
						duration: 2000
					});
					reject(response)
				}
			})
		})
	},
}
